home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / SUN.TRM < prev    next >
Text File  |  1992-03-25  |  7KB  |  283 lines

  1. /*
  2.  * $Id: sun.trm,v 3.26 92/03/24 22:35:43 woo Exp Locker: woo $
  3.  */
  4.  
  5. /* GNUPLOT - sun.trm */
  6. /*
  7.  * Copyright (C) 1990, 1991, 1992   
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *  
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  * 
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *   SUNview windowing system
  25.  *
  26.  * AUTHORS
  27.  *  Maurice Castro
  28.  * 
  29.  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
  30.  * 
  31.  */
  32.  
  33. #include <suntool/sunview.h>
  34. #include <suntool/canvas.h>
  35. #include <suntool/scrollbar.h>
  36. #include <suntool/panel.h>
  37. #include <pixrect/pixrect_hs.h>
  38.  
  39. #define SUN_XMAX 600
  40. #define SUN_YMAX 512
  41.  
  42. #define SUN_VCHAR (12)        /* default, will be changed */
  43. #define SUN_HCHAR (8)        /* default, will be changed */
  44. #define SUN_VTIC (SUN_YMAX/80)
  45. #define SUN_HTIC (SUN_XMAX/80)
  46. #define MARGIN 5
  47. #define MINWIN 128
  48.  
  49. static Frame frame;
  50. static Canvas canvas;
  51. static Pixwin *pw;
  52. static struct pixfont *sun_font = NULL;
  53.  
  54. static enum JUSTIFY sun_justify=LEFT;
  55.  
  56. static Notify_value local_notice_destroy();
  57.  
  58. extern Notify_error notify_dispatch();
  59.   
  60. /* dotted line generator */
  61. unsigned int sun_value = 1;    /* this can be used for colour */
  62. unsigned int sun_line_mask = 0xffff;    /* 16 bit mask for dotted lines */
  63. static unsigned int sun_pattern[] = {0xffff, 0x1111,
  64.     0xffff, 0x5555, 0x3333, 0x7777, 0x3f3f, 0x0f0f, 0x5f5f};
  65. int sun_mask_count = 0;
  66. unsigned int sun_lastx, sun_lasty;    /* last pixel set - used by sun_line */
  67.  
  68.  
  69. SUN_init()
  70. {
  71.   struct termentry *t = &term_tbl[term];
  72.   struct pr_subregion bound;
  73.  
  74.   frame = window_create(NULL, FRAME, 
  75.             FRAME_LABEL,               "Gnuplot",
  76.             0);
  77.   notify_interpose_destroy_func(frame,local_notice_destroy);
  78.   canvas = window_create(frame, CANVAS,
  79.             CANVAS_AUTO_EXPAND,        TRUE,
  80.             CANVAS_AUTO_SHRINK,        TRUE,
  81.             CANVAS_MARGIN,             MARGIN,
  82.             0);
  83.   notify_do_dispatch();
  84.   pw = canvas_pixwin(canvas);
  85.   window_set(frame, WIN_SHOW, TRUE, 0);
  86.  
  87.   /* figure out font and rough size */
  88.   sun_font = pf_default();
  89.   pf_textbound(&bound, 1, sun_font, "M");
  90.   t->v_char = bound.size.y;
  91.   t->h_char = bound.size.x;
  92.  
  93.   return;
  94. }
  95.  
  96. SUN_graphics()
  97. {
  98.   term_tbl[term].xmax = (int) window_get(canvas,CANVAS_WIDTH);
  99.   term_tbl[term].ymax = (int) window_get(canvas,CANVAS_HEIGHT);
  100.   pw_writebackground(pw,0,0,term_tbl[term].xmax, term_tbl[term].ymax, PIX_SRC );
  101.   notify_dispatch();
  102.   /* do not let the user make the window too small */
  103.   if ((term_tbl[term].xmax)<MINWIN)
  104.   {
  105.       window_set(frame,
  106.             WIN_WIDTH,                MINWIN+2*MARGIN+24,
  107.             0);
  108.       notify_dispatch();
  109.       SUN_graphics();
  110.       }
  111.   if ((term_tbl[term].ymax) <MINWIN)
  112.   {
  113.       window_set(frame,
  114.             WIN_HEIGHT,               MINWIN+2*MARGIN+24,
  115.             0);
  116.       notify_dispatch();
  117.       SUN_graphics();
  118.       }
  119.   notify_dispatch();
  120.   return;
  121. }
  122.  
  123. SUN_text()
  124. {
  125.   notify_dispatch();
  126.   return; /* enter text from another window!!! */
  127. }
  128.  
  129. SUN_linetype(linetype)
  130. int linetype;
  131. {
  132.     if (linetype>=7)
  133.         linetype %= 7;
  134.     sun_line_mask = sun_pattern[linetype+2];
  135.     sun_mask_count=0;
  136. }
  137.  
  138.  
  139. SUN_move(x, y)
  140. unsigned int x, y;
  141. {
  142.   sun_lastx = x;
  143.   sun_lasty = y;
  144.   notify_dispatch();
  145.   return;
  146. }
  147.  
  148. SUN_vector(x, y)
  149. unsigned int x, y;
  150. {
  151.   if ( (x>=term_tbl[term].xmax) || (y>=term_tbl[term].ymax) )
  152.     return;
  153.   sun_line(sun_lastx,x,sun_lasty,y);
  154.   canvas_pixwin(canvas);
  155.   notify_dispatch();
  156.   return;
  157. }
  158.  
  159.  
  160. SUN_put_text(x,y,str)
  161. unsigned int x, y;
  162. char *str;
  163. {
  164.   struct pr_subregion bound;
  165.  
  166.   if ( (x>=term_tbl[term].xmax) || (y>=term_tbl[term].ymax) )
  167.     return;
  168.  
  169.   pf_textbound(&bound, strlen(str), sun_font, str);
  170.   y = term_tbl[term].ymax-1-y + bound.size.y/3; /* vertical centering */
  171.  
  172.   switch(sun_justify) {
  173.      case LEFT:   break;
  174.      case CENTRE: x -= bound.size.x/2; break;
  175.      case RIGHT:  x -= bound.size.x; break;
  176.   }
  177.   pw_text(pw, x,y, PIX_SRC | PIX_DST, 0, str); 
  178.   canvas_pixwin(canvas);
  179.   notify_dispatch();
  180.   return;
  181. }
  182.  
  183.  
  184. int SUN_justify_text(mode)
  185.     enum JUSTIFY mode;
  186. {
  187.     sun_justify = mode;
  188.     return (TRUE);
  189. }
  190.   
  191.   
  192.  
  193.  
  194. SUN_reset()
  195. {
  196.   
  197.   term_tbl[term].xmax = SUN_XMAX;
  198.   term_tbl[term].ymax = SUN_YMAX;
  199.   window_set(frame, WIN_SHOW, FALSE, 0);
  200.   return;
  201. }
  202.  
  203.  
  204.  
  205. sun_setmaskpixel(x,y,value)
  206. unsigned int x,y,value;
  207. {
  208.     /* dotted line generator */
  209.     if ((sun_line_mask>>sun_mask_count)&(unsigned int)(1)) {
  210.         pw_put(pw,x,term_tbl[term].ymax-1-y,sun_value);
  211.     }
  212.     sun_mask_count= (sun_mask_count+1) % 16;
  213.     sun_lastx= x;  /* last pixel set with mask */
  214.     sun_lasty= y;
  215. }
  216.  
  217.  
  218.  
  219.  
  220. sun_line(x1,x2,y1,y2)
  221. unsigned int x1,x2,y1,y2;
  222. {
  223. int runcount;
  224. int dx,dy;
  225. int xinc,yinc;
  226. unsigned int xplot,yplot;
  227.  
  228.     runcount=0;
  229.     dx = abs((int)(x1)-(int)(x2));
  230.     if (x2>x1)  xinc=  1;
  231.     if (x2==x1) xinc=  0;
  232.     if (x2<x1)  xinc= -1;
  233.     dy = abs((int)(y1)-(int)(y2));
  234.     if (y2>y1)  yinc=  1;
  235.     if (y2==y1) yinc=  0;
  236.     if (y2<y1)  yinc= -1;
  237.     xplot=x1;
  238.     yplot=y1;
  239.     if (dx>dy) {
  240.         /* iterate x */
  241.         if ( (sun_line_mask==0xffff) ||
  242.             ((xplot!=sun_lastx) && (yplot!=sun_lasty)) )
  243.             sun_setmaskpixel(xplot,yplot,sun_value);
  244.         while (xplot!=x2) { 
  245.             xplot+=xinc;
  246.             runcount+=dy;
  247.             if (runcount>=(dx-runcount)) {
  248.                 yplot+=yinc;
  249.                 runcount-=dx;
  250.             }
  251.             sun_setmaskpixel(xplot,yplot,sun_value);
  252.         } 
  253.     } else {
  254.         /* iterate y */
  255.         if ( (sun_line_mask==0xffff) ||
  256.             ((xplot!=sun_lastx) && (yplot!=sun_lasty)) )
  257.             sun_setmaskpixel(xplot,yplot,sun_value);
  258.         while (yplot!=y2) {
  259.             yplot+=yinc;
  260.             runcount+=dx;
  261.             if (runcount>=(dy-runcount)) {
  262.                 xplot+=xinc;
  263.                 runcount-=dy;
  264.             }
  265.             sun_setmaskpixel(xplot,yplot,sun_value);
  266.         } 
  267.     }
  268. }
  269.  
  270.  
  271. static Notify_value local_notice_destroy(frame, status)
  272.    Frame frame;
  273.    Destroy_status status;
  274. {
  275.    if (status != DESTROY_CHECKING)
  276.    {
  277.       SUN_reset();
  278.       term_init = FALSE;
  279.       }
  280.    return(NOTIFY_DONE);
  281.    }
  282.  
  283.